<?php
/**
 * “新浪微博”刷粉丝
 * 
 * @author linsir123
 */
class LxsWeibo
{
	/**
	 * @var 客户端
	 */
	public $client;
	
	/**
	 * @var 当前用户
	 */
	public $me;
	
	/**
	 * 构造函数
	 */
	function __construct($token)
	{
		include_once( 'config.php' );
		include_once( 'saetv2.ex.class.php' );
		
		/// 
		ob_start();
		session_start();
		set_time_limit(0);
		header('Content-Type: text/html; charset=utf-8');
		if (function_exists('date_default_timezone_set')) 
			date_default_timezone_set('Asia/ShangHai');
			
		///
		$this->client = new SaeTClientV2(WB_AKEY, WB_SKEY, $token);
		$uidGet = $this->client->get_uid();
		$this->me = $this->client->show_user_by_id($uidGet['uid']);
	}
	
	/**
	 * 开始
	 */
	function run()
	{
		pr("----------------------".date('Y-m-d H:i:s')."----------------------");
		pr($this->me);
		$this->unFollow();
		$this->follow();
	}
	
	/**
	 * 取消关注
	 */
	function unFollow($num = 20)
	{
		pr("----------------------unFollow----------------------");
		
		///
		$uId = $this->me['id'];
		$list = $this->client->friends_ids_by_id($uId, 0, 10);
		
		///
		$i = 0;
		foreach ($list['ids'] as $id) {
			$flag = $this->client->unfollow_by_id($id);
			pr($flag);
			sleep(3);
		}
	}
	
	/**
	 * 关注
	 */
	function follow($num = 10)
	{
		$uid = $this->getUser();
		pr("----------------------follow[{$uid}]----------------------");
		
		///
		
	}
	
	/**
	 * 取得某个名人
	 */
	function getUser()
	{
		$list =	array (
			0 => '1644395354',
			1 => '1713926427',
			2 => '1644572034',
			3 => '1252373132',
			4 => '1735618041',
			5 => '1671526850',
			6 => '1657421782',
			7 => '1660209951',
			8 => '1236380405',
			9 => '1675718025',
			10 => '1642635773',
			11 => '1657430300',
			12 => '1097201945',
			13 => '1567852087',
			14 => '1615743184',
		);
		
		///
		$i = mt_rand(0, count($list) - 1);
		return $list[$i];
	}
	
	/**
	 * 日志
	 */
	function writeLog($id, $result, $name = '_follow')
	{
		static $i = 0;
		
		///
		++$i;
		if ( ! isset($result['error'])) {
			pr($i. ": " .$result['id']);
		} else {
			pr($i. ": " .$id);
			pr($result);
		}
	}
}

/**
 * 调试
 */
function pr($var)
{
	echo '<pre>';
	print_r($var);
	echo '</pre>';
	ob_flush();
    flush();
}
